import { uploadUserBehavior } from "@/api/index";
export const playSongs = (currentSong) => {
    uni.setStorageSync('currentSong', currentSong)

    let songs:[] = uni.getStorageSync('songs')
    console.log("songs:-----",songs);
    
    if (!songs) {
        songs = []
        songs.push(currentSong)
        uni.setStorageSync('songs', songs)
    }else{
        let song = songs.find(item => item.musicId === currentSong.musicId)
        console.log(song);
        
        if (!song) {
            songs.push(currentSong)
            uni.setStorageSync('songs', songs)
        }
    }
    console.log(currentSong);
    
    uploadUserBehavior(currentSong.musicId).then(res => {

        uni.switchTab({ url: '/pages/music/index' })
    })
    console.log('开始上传数据');
    
    // todo: 这里需要向后台发送播放的歌曲信息用于统计
} 